<template>
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['goods:directory:add']"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['goods:directory:edit']"
            >修改</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['goods:directory:remove']"
            >删除</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['goods:directory:export']"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
  
      <el-table
        @selection-change="handleSelectionChange"
        fit
        v-loading="loading"
        border
        :data="dataList"
      >
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column
          min-width="150"
          label="名称"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <el-link @click="handleDetail(scope.row)" type="primary">{{
              scope.row.name
            }}</el-link>
          </template>
        </el-table-column> -->
        <el-table-column label="序号" width="50px" type="index" />
        <el-table-column
          show-overflow-tooltip
          label="部门"
          min-width="150"
          prop="deptName"
        />
        <el-table-column
          :show-overflow-tooltip="true"
          min-width="120"
          label="软件名称"
          prop="softwareLabel"
        >
        </el-table-column>
        <!-- <el-table-column
          show-overflow-tooltip
          label="技术指标"
          min-width="150"
          prop="tecTarget"
        /> -->
        <el-table-column
          show-overflow-tooltip
          min-width="150"
          label="版本号"
          prop="versionValue"
        />
  
        <el-table-column
          show-overflow-tooltip
          min-width="150"
          label="核查方式"
          prop="checkLabel"
        />
        <el-table-column
          show-overflow-tooltip
          label="核查内容"
          width="150"
          prop="contentLabel"
        />
  
        <el-table-column
          show-overflow-tooltip
          min-width="150"
          label="计划实施时间"
          prop="startTime"
        />
        <el-table-column
          show-overflow-tooltip
          min-width="150"
          label="参加人员"
          prop="userName"
        />
        <el-table-column
          show-overflow-tooltip
          min-width="150"
          label="备注"
          prop="remark"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="240"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              v-hasPermi="['goods:directory:info']"
              @click="handleDetail(scope.row)"
              >详情</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['goods:directory:edit']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['goods:directory:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>
  
  <script>
  import {
    listgoodsDirectory,
    delgoodsDirectory,
    effectgoodsDirectory,
  } from "@/api/quality/goods/directory.js";
  import {
    listAutoDeviceYearPlan,
  } from "@/api/quality/computer/plan.js";
  export default {
    name: "directory",
    data() {
      return {
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        dataList: [],
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          chemicals:0,
          name: undefined,
        },
        // 日期范围
        dateRange: [],
  
        userList: [],
        deptOptions: [],
      };
    },
    created() {
      this.getList();
      this.getDeptTree();
    },
    methods: {
      handleStatusChange(row) {
        let text = row.effectStatus === "1" ? "启用" : "禁用";
        this.$modal
          .confirm('确认要"' + text + '""' + row.name + '"目录吗？')
          .then(function () {
            return effectgoodsDirectory(
              row.chemistryGoodsDirectoryId,
              row.effectStatus
            );
          })
          .then(() => {
            this.$modal.msgSuccess(text + "成功");
          })
          .catch(function () {
            row.effectStatus = row.effectStatus === "0" ? "1" : "0";
          });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.chemistryGoodsDirectoryId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
  
      /** 修改按钮操作 */
      handleUpdate(row) {
        const configId = row.chemistryGoodsDirectoryId || this.ids;
        this.$router.push("./addPlan?isEdit=true&id=" + configId);
      },
      handleDetail(row) {
        this.$router.push(
          "./addPlan?isInfo=true&id=" + row.chemistryGoodsDirectoryId);
      },
  
      /** 删除按钮操作 */
      handleDelete(row) {
        const configId = row.chemistryGoodsDirectoryId || this.ids;
        let name = this.checkRow(
          configId,
          this.dataList,
          "chemistryGoodsDirectoryId",
          "DELETE",
          "name"
        );
        this.$modal
          .confirm('是否确认删除名称为"' + name + '"的数据项？')
          .then(function () {
            return delgoodsDirectory(configId);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      },
      handleAdd() {
        this.$router.push("./addPlan");
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        listAutoDeviceYearPlan({
          ...this.addDateRangeTime(
            this.queryParams,
            this.dateRange,
            "startEndDate",
            "endEndDate"
          ),
        }).then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
  
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleExport() {
        this.download(
          "system/goodsDirectory/export",
          {
            ...this.queryParams,
          },
          `消耗品、标准物质、化学药品名录表_${this.parseTime(
            new Date().getTime(),
            "{y}-{m}-{d}"
          )}.xlsx`
        );
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
    },
  };
  </script>
  <style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    img {
      width: 100%;
    }
  }
  </style>
  